package com.ruoyi.biz.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 常用的数据公式
 */
public abstract class MathUtil {
    
    public static BigDecimal multiple100(BigDecimal num) {
        if(num == null) {
            return null;
        }
        return num.multiply(new BigDecimal("100"));
    }

    public static BigDecimal multiple1000(BigDecimal num) {
        if(num == null) {
            return null;
        }
        return num.multiply(new BigDecimal("1000"));
    }

    public static BigDecimal divide100(BigDecimal num) {
        return divide100(num, 2);
    }

    public static BigDecimal divide100(BigDecimal num, int scale) {
        return divide100(num, scale, RoundingMode.HALF_UP);
    }

    public static BigDecimal divide100(BigDecimal num, int scale, RoundingMode roundingMode) {
        if(num == null) {
            return null;
        }
        return num.divide(new BigDecimal("100"), scale, roundingMode);
    }

    public static BigDecimal divide1000(BigDecimal num) {
        return divide1000(num, 3);
    }

    public static BigDecimal divide1000(BigDecimal num, int scale) {
        return divide1000(num, scale, RoundingMode.HALF_UP);
    }

    public static BigDecimal divide1000(BigDecimal num, int scale, RoundingMode roundingMode) {
        if(num == null) {
            return null;
        }
        return num.divide(new BigDecimal("1000"), scale, roundingMode);
    }
}
